package com.mrs.controller;

import com.mrs.common.ResponseResult;
import com.mrs.common.constants.SystemConstants;
import com.mrs.dto.AddCommentDto;
import com.mrs.entity.Comment;
import com.mrs.service.CommentService;
import com.mrs.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description: CommentController
 * date: 2022/8/9 19:25
 * author: MR.孙
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论",description = "评论相关接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //获取评论列表
    @GetMapping("/commentList")
    @ApiOperation(value = "评论列表",notes = "添加一条评论")
    @ApiImplicitParams(
            {       @ApiImplicitParam(name = "articleId",value = "文章id"),
                    @ApiImplicitParam(name = "pageNum",value = "页码"),
                    @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            }
    )
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize){
        //根据第一个参数判断这是文章还是友链
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }

    //友链评论列表
    @GetMapping("/linkCommentList")
    @ApiOperation(value = "友链评论列表",notes = "获取一页友链评论")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNum",value = "页码"),
                    @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            }
    )
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){
        //根据第一个参数判断这是文章还是友链
        return commentService.commentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }



    //添加评论
    @PostMapping
    @ApiOperation(value = "添加评论",notes = "获取一页友链评论")
    @ApiImplicitParam(name = "comment",value = "前台传递的评论信息")
    public ResponseResult addComment(@RequestBody AddCommentDto addCommentDto){
        Comment comment = BeanCopyUtils.copyBean(addCommentDto, Comment.class);
        return commentService.addComment(comment);
    }


}
